﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ibba.src.norisk
{
    public partial class MainPage : UserControl
    {
        bool barraCarregada;

        public MainPage()
        {
            InitializeComponent();
            barraMenu.User = AppHelper.NomeUsuario;
            barraMenu.TitleBar = "Menu";
        }

        private void ContentFrame_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
        }

        private void MainPageModeloLM(bool LM)
        {
            if (LM == false)
            {
                //barraPesquisa.Visibility = System.Windows.Visibility.Collapsed;
                barraMenu.Visibility = System.Windows.Visibility.Collapsed;

                ContentFrame.SetValue(Grid.RowProperty, 0);
                ContentFrame.SetValue(Grid.RowSpanProperty, 3);
            }
            else
            {

                if (barraCarregada == false)
                {
                    //barraPesquisa.Carregar();
                    barraCarregada = true;
                }

                barraMenu.Visibility = System.Windows.Visibility.Visible;
                //barraPesquisa.Visibility = System.Windows.Visibility.Visible;
                //barraPesquisa.CampoPesquisaVisivel = System.Windows.Visibility.Visible;

                //ContentFrame.SetValue(Grid.RowProperty, 1);
                //ContentFrame.SetValue(Grid.RowSpanProperty, 1);
            }

        }

        // If an error occurs during navigation, show an error window
        private void ContentFrame_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
        {
            e.Handled = true;

            MessageBoxHelper.ShowErro("Erro!"
                                     , "Página não encontrada: \n\n" + e.Uri.ToString()
                                     , String.Format("{1}{0}{0}{2}", Environment.NewLine, e.Exception.Message, e.Exception.StackTrace));

        }

        private void ContentFrame_Navigating(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            barraMenu.ClearButtons();
            MainPageModeloLM(true);
        }

        public void NavigateTo(string uri)
        {
            ContentFrame.Navigate(new Uri(uri, UriKind.Relative));
        }

        public void NavigateTo(string uri, UriKind pUriKind)
        {
            ContentFrame.Navigate(new Uri(uri, pUriKind));
        }
    }
}
